// pages/status/index.js
import {
    baseUrl
} from "../../utils/request"
Page({
    /**
     * 页面的初始数据
     */
    data: {
        info: ""
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        this.setData({
            info: options.data
        })
    },
    login() {
        this.setData({
            info: "登录中..."
        })
        wx.showLoading({
            title: '登录中...',
        })
        // 登录
        let that = this
        wx.login({
            success: res => {
                var code = res.code
                wx.request({
                    url: baseUrl() + '/user/login',
                    // url:'http://test.com/user/login',
                    data: {
                        code: code
                    },
                    method: "POST",
                    header: {
                        'content-type': 'application/json' // 默认值
                    },
                    success(res) {
                        if (res.data.code != 1) {
                            wx.showToast({
                                title: res.data.message,
                                icon: "none"
                            })
                            that.setData({
                                info: res.data.message
                            })
                        } else {
                            wx.setStorageSync('token', res.data.data)
                            wx.switchTab({
                                url: '../index/index'
                            })
                        }
                    }
                })
                wx.hideLoading()
            }
        })
    }
})